package com.quanyan.user.service.admin.impl;

import com.quanyan.common.Plugin.PageObj;
import com.quanyan.user.mapper.UserAdminMapper;
import com.quanyan.user.model.vo.request.admin.ReqUserAccountBindQuery;
import com.quanyan.user.model.vo.response.admin.RespUserAccountBindInfo;
import com.quanyan.user.service.admin.UserAccountBindService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by hua on 2016/9/19.
 */
@Service
public class UserAccountBindServiceImpl implements UserAccountBindService {
    private final static Logger logger = LoggerFactory.getLogger(UserAccountBindServiceImpl.class);

    @Autowired
    private UserAdminMapper userAdminMapper;

    @Override
    public PageObj<List<RespUserAccountBindInfo>> queryUserAccountBindList(ReqUserAccountBindQuery userAccountBindQuery) {
        List<RespUserAccountBindInfo> userAccountBindInfos = null;
        int pageNo = userAccountBindQuery.getPageNo();
        int total = 0;
        try {
            userAccountBindQuery.setPageNo((userAccountBindQuery.getPageNo()) * userAccountBindQuery.getPageSize());
            userAccountBindInfos = userAdminMapper.queryUserAccountBindList(userAccountBindQuery);
            total = userAdminMapper.selectAccountBindCountByQuery(userAccountBindQuery);
        } catch (Exception e) {
            logger.error("获取用户账号绑定列表失败！", e.getMessage());
        }
        return PageObj.create(total, pageNo, userAccountBindQuery.getPageSize(), userAccountBindInfos);
    }
}
